package main

import "fmt"

func main() {
	nums := []int{3, 0, 1}
	fmt.Println(missingNumber(nums))
}

//#link: https://leetcode-cn.com/problems/missing-number/
/**
 * @Description: 思路: 求出目标和，然后对数组做减法
 */
func missingNumber(nums []int) int {
	// 1.记录 0 到 N 的sum值
	targetSum := 0
	for i := 0; i <= len(nums); i++ {
		targetSum += i
	}
	// 2.记录数组的和
	for _, num := range nums {
		targetSum -= num
	}
	return targetSum
}
